package com.demo.java.netty.pipeline;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.nio.charset.Charset;

public class InboundHandler2 extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf buf = (ByteBuf) msg;
        System.out.println("channel read inbound2, read msg:" + buf.toString(Charset.defaultCharset()));

//        ctx.pipeline().writeAndFlush(Unpooled.copiedBuffer("server response: " + buf.toString(Charset.defaultCharset()), Charset.defaultCharset()));
//        ctx.channel().writeAndFlush(Unpooled.copiedBuffer("server response: " + buf.toString(Charset.defaultCharset()), Charset.defaultCharset()));
        ctx.writeAndFlush(Unpooled.copiedBuffer("server response: " + buf.toString(Charset.defaultCharset()), Charset.defaultCharset()));
    }
}
